﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;

namespace TextGenerator
{
    public partial class InstructionsDialog : Form
    {
        /// <summary>
        /// The font to be used for regular, non-highlighted text.
        /// </summary>
        private readonly Font fntRegular = new Font("Courier New", 8, FontStyle.Regular);

        /// <summary>
        /// The font to be used for high-lighted text.
        /// </summary>
        private readonly Font fntBold = new Font("Courier New", 8, FontStyle.Bold);


        /// <summary>
        /// Initializes a new instance of the <see cref="InstructionsDialog"/> class. 
        /// </summary>
        public InstructionsDialog()
        {
            InitializeComponent();
        }

        private void frmHelp_Load(object sender, EventArgs e)
        {
            // Set up the description box.

            // Concatenate the description string.
            string symbols = String.Format(
                "{1}\tThe prefix identifying a token.{0}{2}\tThe suffix identifying a token.{0}{3}\tToken member separator.{0}{4}\t(Inside a token, followed by a number.) Token referencing to the specified zero-based token index.{0}\\{5}\t(Inside a quoted string, inside a token.) Quotation mark (e.g. \"\\\"\").", 
                Environment.NewLine, 
                Permutator.SYMBOL_DELIMITER_PREFIX, 
                Permutator.SYMBOL_DELIMITER_SUFFIX, 
                Permutator.TOKEN_DIVISOR, 
                Permutator.REFERENCE_IDENTIFIER_PREFIX, 
                Permutator.QUOTATION_MARK);
            this.richTextBox1.Text = symbols;

            // Format the text.
            int idxPrefix = symbols.IndexOf(Permutator.SYMBOL_DELIMITER_PREFIX);
            int idxSuffix = symbols.IndexOf(Permutator.SYMBOL_DELIMITER_SUFFIX) - 1;
            int idxDivisor = symbols.IndexOf(Permutator.TOKEN_DIVISOR) - 2;
            int idxReference = symbols.IndexOf(Permutator.REFERENCE_IDENTIFIER_PREFIX) - 3;
            int idxQuotation = symbols.IndexOf(Permutator.QUOTATION_MARK) - 5;

            this.richTextBox1.SelectionStart = idxPrefix;
            this.richTextBox1.SelectionLength = Permutator.SYMBOL_DELIMITER_PREFIX.Length;
            this.richTextBox1.SelectionFont = this.fntBold;

            this.richTextBox1.SelectionStart = idxSuffix;
            this.richTextBox1.SelectionLength = Permutator.SYMBOL_DELIMITER_SUFFIX.Length;
            this.richTextBox1.SelectionFont = this.fntBold;

            this.richTextBox1.SelectionStart = idxDivisor;
            this.richTextBox1.SelectionLength = Permutator.TOKEN_DIVISOR.Length;
            this.richTextBox1.SelectionFont = this.fntBold;

            this.richTextBox1.SelectionStart = idxReference;
            this.richTextBox1.SelectionLength = Permutator.REFERENCE_IDENTIFIER_PREFIX.Length;
            this.richTextBox1.SelectionFont = this.fntBold;

            this.richTextBox1.SelectionStart = idxQuotation;
            this.richTextBox1.SelectionLength = Permutator.QUOTATION_MARK.Length + 1;
            this.richTextBox1.SelectionFont = this.fntBold;


            // Set up rich text boxes.
            int[] tabstops = { 20, 40, 60 };
            this.rtbPattern1.SelectionTabs = tabstops;
            this.rtbPattern2.SelectionTabs = tabstops;
            this.rtbPattern4.SelectionTabs = tabstops;
            this.rtbResults1.SelectionTabs = tabstops;
            this.rtbResults2.SelectionTabs = tabstops;
            this.rtbResults3.SelectionTabs = tabstops;
            this.rtbResults4.SelectionTabs = tabstops;
            this.rtbResults5.SelectionTabs = tabstops;

            this.rtbPattern1.Font = this.fntRegular;
            this.rtbPattern2.Font = this.fntRegular;
            this.rtbPattern3.Font = this.fntRegular;
            this.rtbPattern4.Font = this.fntRegular;
            this.rtbPattern5.Font = this.fntRegular;

            this.rtbResults1.Font = this.fntRegular;
            this.rtbResults2.Font = this.fntRegular;
            this.rtbResults3.Font = this.fntRegular;
            this.rtbResults4.Font = this.fntRegular;
            this.rtbResults5.Font = this.fntRegular;


            // Create examples.
            string pattern = String.Empty;
            string results = String.Empty;
            Permutator permutator;


            // Example #1.

            // Generate permutations.
            pattern = String.Format(@"[[Music|Speech]]_[[22|44|48|96]]kHz_[[96|128|160]]kbps.wav");
            permutator = new Permutator(false);
            permutator.Initialize(null, null, pattern);
            permutator.Generate();
            
            // Concatenate the result.
            results = String.Empty;
            foreach (string s in permutator.Permutations)
                results += s + Environment.NewLine;

            // Fill the rich text boxes.
            this.rtbPattern1.Text = pattern;
            this.rtbResults1.Text = results;


            // Example #2.

            // Generate permutations.
            pattern = String.Format(@"Test Case: Scenario [[A|B|C]], Variation [[1|2|3|4]] (id [[\0]]:[[\1]])");
            permutator = new Permutator(false);
            permutator.Initialize(null, null, pattern);
            permutator.Generate();

            // Concatenate the result.
            results = String.Empty;
            foreach (string s in permutator.Permutations)
                results += s + Environment.NewLine;

            // Fill the rich text boxes.
            this.rtbPattern2.Text = pattern;
            this.rtbResults2.Text = results;


            // Example #3.

            // Generate permutations.
            pattern = "[[HEAACv1|HEAACv2|MPEG3]] [[11|22|44]]kHz [[16|32|64]]kbps [[Mono|Stereo]] => [[\\0|EnhAAC|EnhAacPlus|Mpeg3]]_[[\\2]]kbps.[[\\0|aac|aac|mp3]]";
            permutator = new Permutator(false);
            permutator.Initialize(null, null, pattern);
            permutator.Generate();

            // Concatenate the result.
            results = String.Empty;
            foreach (string s in permutator.Permutations)
                results += s + Environment.NewLine;

            // Fill the rich text boxes.
            this.rtbPattern3.Text = pattern;
            this.rtbResults3.Text = results;


            // Example #4.

            // Generate permutations.
            pattern = "public void test_[[PCM]]_[[8|11|12|16|22|24|32|44|48|96]]kHz_[[Mono|Stereo]]_[[WAV|RAW]]_01() {";
            pattern += Environment.NewLine;
            pattern += "\tString audioFile = \"[[\\0]]_[[\\3]]_Music_180sec_[[\\2]]_[[\\1]]kHz.wav\";";
            pattern += Environment.NewLine;
            pattern += "\tString LOG_TAG = \"TC_PlayStop_[[\\0]]_[[\\1]]kHz_[[\\2]]_[[\\3]]_01\";";
            pattern += Environment.NewLine;
            pattern += Environment.NewLine;
            pattern += "\tScenario(LOG_TAG, audioFile);";
            pattern += Environment.NewLine;
            pattern += "}";
            pattern += Environment.NewLine;
            permutator = new Permutator(false);
            permutator.Initialize(null, null, pattern);
            permutator.Generate();

            // Concatenate the result.
            results = String.Empty;
            foreach (string s in permutator.Permutations)
                results += s + Environment.NewLine;

            // Fill the rich text boxes.
            this.rtbPattern4.Text = pattern;
            this.rtbResults4.Text = results;


            // Example #5.

            // Generate permutations.
            pattern = "[[\"HE-AAC v1\"|\"HE-AAC v2 (\\\"Enhanced AAC Plus\\\")\"|MPEG3]] [[Mono|Stereo|\"5.1\"]]";
            permutator = new Permutator(false);
            permutator.Initialize(null, null, pattern);
            permutator.Generate();

            // Concatenate the result.
            results = String.Empty;
            foreach (string s in permutator.Permutations)
                results += s + Environment.NewLine;

            // Fill the rich text boxes.
            this.rtbPattern5.Text = pattern;
            this.rtbResults5.Text = results;
        }
    }
}
